/**
 *  @file ApplicationPanel.java
 *  @author Mamontov
 *
 *  A panel of application
 */
package db21;

import db21.entities.Subjects;
import db21.listeners.ClickOnlyListener;
import java.awt.event.MouseEvent;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JList;
import javax.swing.JTextField;

/**
 * @class  ApplicationPanel
 * @author Mamontov
 * A panel of application is connected to other
 *
 */
public class ApplicationPanel extends javax.swing.JPanel {
    
    protected Application m_model;
    
    
    protected void individualCreated(String name)  {
        
    }
  
    
    
    protected void bindOnClickListenerTogglingToMode(JButton b, ApplicationMode m) {
        b.addMouseListener(new ModeChangingClickListener(this, m));
    }
    
    public void setModel(Application model) {
        this.m_model = model;
    }
    
    protected Application model() {
        return m_model;
    }
    
    protected void bindSave(JButton b)  {
        b.addMouseListener(new ClickOnlyListener() {

            @Override
            public void mouseClicked(MouseEvent e) {
                ApplicationPanel.this.model().save();
            }
        });
    }
    
    
    public void fireModelUpdate() {
        
    }

    private static class ModeChangingClickListener extends ClickOnlyListener {
        ApplicationPanel m_panel;
        ApplicationMode m_mode;
        
        
        public ModeChangingClickListener(ApplicationPanel panel, ApplicationMode m) {
            m_panel = panel;
            m_mode = m;
        }

        @Override
        public void mouseClicked(MouseEvent e) {
            this.m_panel.m_model.setMode(this.m_mode);
        }
    }
    
}
